package jianzhiOffer;

public class num18 {
    public ListNode deleteNode(ListNode head, int val) {
        ListNode dummyhead = new ListNode(-1);
        dummyhead.next = head;
        ListNode cur = head;
        ListNode prev = dummyhead;
        while(cur != null) {
            if(cur.val == val) {
                prev.next = cur.next;
                cur.next = null;
            }
            cur = cur.next;
            prev = prev.next;
        }
        return dummyhead.next;
    }
}
